package com.jz.main.io.nio;

import java.util.*;

public class ThouTest {
    static class Node{
        private int data; // 节点数据
        public Node(int data) {
            this.data = data;
        }
        public int getData() {
            return data;
        }
        public void setData(int data) {
            this.data = data;
        }
    }
    static class Arr{
        private int cur; // 当前节点
//        private int end; // 尾 数据索引
        private int[] blongs; // 所属数组片
        private Arr last; //上节点
        private Arr next; //下节点
        public int cur(){
            return blongs[this.cur];
        }
        public int next(){
            return blongs[++this.cur];
        }
        public int[] next(int index){
            cur = cur + 10;
            int[] tar = new int[10];
            System.arraycopy(blongs, cur-10, tar, 0, 10);
            return tar;
        }
        public Arr getLast() {
            return last;
        }
        public void setLast(Arr last) {
            this.last = last;
        }
        public Arr getNext() {
            return next;
        }
        public void setNext(Arr next) {
            this.next = next;
        }
        public void setNode(Arr last,Arr next) {
            this.last = last;
            this.next = next;
        }
        public int[] getBlongs() {
            return blongs;
        }
        public void setBlongs(int[] blongs) {
            this.blongs = blongs;
        }
        Arr(int[] blongs){
            this.blongs = blongs;
            this.cur = 0;
//            this.end = blongs[blongs.length-1];
        }
    }
    public static void main(String[] args) {

        int sum = 800;
        int[] source = new int[sum];
        int[] sourceCopy = new int[sum];
        for (int i = 1; i <= sum; i++) {
            source[i-1] = (int) (Math.random()*(sum*2-1-i)*i);
            sourceCopy[i-1] = source[i-1];
        }

        Map<Integer,int[]> map = new HashMap<>();
        int size = 40;
        for (int i = 0; i < sum/size; i++) {
            int[] arr = new int[size];
            System.arraycopy(source, i*size, arr, 0, size);
            map.put(i,arr);
        }
        List<Arr> list = new ArrayList<>();
        map.values().forEach(ints->{
            MergeSort.mergeSort(ints);
            list.add(new Arr(ints));
        });
        list.sort(new Comparator<Arr>() {
            @Override
            public int compare(Arr o1, Arr o2) {
                return o1.cur()-o2.cur();
            }
        });
        for (int i = 0; i < list.size(); i++) {

        }

//        for (int i = 0; i < list.size(); i++) {
//            if (i==0){
//                list.get(i).setNext(list.get(i+1));
//            }else if(i == list.size()-1){
//                list.get(i).setLast(list.get(i-1));
//            }else{
//                list.get(i).setNode(list.get(i-1),list.get(i+1));
//            }
//        }
        Arr[] arrs = list.toArray(new Arr[]{});
        int index = 0;
        int count = 0;
        while (count<size){
//            arrs[0]
            count++;
        }




















        //   数据校验
        List<Integer> tarList = new ArrayList<>(sum);
        map.values().forEach(ints->{
            for (int anInt : ints) {
                tarList.add(anInt);
            }
        });
        int[] tar = new int[sum];
        for (int i = 0; i < tar.length; i++) {
            tar[i] = tarList.get(i);
        }
        MergeSort.mergeSort(tar);
        MergeSort.mergeSort(sourceCopy);
        for (int i = 0; i < sum; i++) {
            if (tar[i] == sourceCopy[i]){
//                System.out.println(tar[i] +","+ sourceCopy[i]);
            }else{
                System.out.println("数据不一致");
                return;
            }
        }

    }
}
